<?php
/*****************************************************************
 * Fusion.Board
 *
 * @author                Denis Wrobel
 * @license               http://www.gnu.org/licenses/gpl-3.0.html
 * @version               0.1
 *
 *****************************************************************/

if( !defined( 'IN_SCRIPT' ) )
{
    die( 'Go Away!' );
}


$forum = new Forum;
$forums = $forum->fetchForums();

foreach( $forums AS $category )
{
    $forum_list = '';
    
    foreach( $category['forums'] AS $forums )
    {
        
        $forum_list .= $template->assignBlock( 'forumIndexStyle', array( 'forum_id'          => $forums['forum_id'],
                                                                         'forum_name'        => $core->htmlFilter( $forums['forum_name'] ),
                                                                         'forum_description' => $core->htmlFilter( $forums['forum_description'] ),
                                                                         'forum_posts'       => $forums['forum_posts'],
                                                                         'forum_topics'      => $forums['forum_topics'],
                                                                         'forum_link'        => 'index.php?action=forumview&f=' . $forums['forum_id'] ) );
    }
    
    $template->setLoop( 'categories', array( 'category_name' => $core->htmlFilter( $category['category_name'] ),
                                             'forums'        => $forum_list ) );
}

$online = $core->usersOnline();

if( $online['users_count'] )
{
    foreach( $online['users'] AS $online_user )
    {
        $template->setLoop( 'users_online', array( 'username'    => $core->colorUsername( $online_user['group_style'], $core->htmlFilter( $online_user['username'] ) ),
                                                   'a_user_link' => 'index.php?action=usercp&mode=view&u=' . $online_user['user_id'] ) );
    }
}

$template->assignVars( array( 'l_stats_and_info'             => $language->string( 'stats_and_info' ),
                              'users_online_in_last_minutes' => $language->sprintf( '{1} {2} {3}', $language->string( 'users_online_in_last' ),
                                                                                                   $board['stat_time'],
                                                                                                   $language->string( 'minutes', 0 ) ),
                              'users_online_count'           => $language->sprintf( '{1} <b>{2}</b> {3}, {4} <b>{5}</b> {6} {7} <b>{8}</b> {9}', $language->string( 'forum_is_browsed_by' ),
                                                                                                                                                 $online['all'],
                                                                                                                                                 ( $online['all'] == 1 ) ? $language->string( 'one_person', 0 ) : $language->string( 'few_persons', 0 ),
                                                                                                                                                 $language->string( 'in_this', 0 ),
                                                                                                                                                 $online['users_count'],
                                                                                                                                                 ( $online['users_count'] == 1 ) ? $language->string( 'one_user', 0 ) : $language->string( 'few_users', 0 ),
                                                                                                                                                 $language->string( 'and', 0 ),
                                                                                                                                                 $online['guests'],
                                                                                                                                                 ( $online['guests'] == 1 ) ? $language->string( 'one_guest', 0 ) : $language->string( 'few_guests', 0 )) ) );


$stats = $core->boardStats( $online['all'] );

$template->assignVars( array( 'users_stats' => $language->sprintf( '{1} <b>{2}</b> {3}', $language->string( 'we_have' ),
                                                                                         $stats['users'],
                                                                                         $language->string( 'registered_users', 0 ) ),
                              'posts_stats' => $language->sprintf( '{1} <b>{2}</b> {3} {4} <b>{5}</b> {6}', $language->string( 'our_users_posted' ),
                                                                                                            $stats['posts'],
                                                                                                            $language->string( 'posts', 0 ),
                                                                                                            $language->string( 'in', 0 ),
                                                                                                            $stats['topics'],
                                                                                                            $language->string( 'topics', 0 ) ),
                              'most_users'  => $language->sprintf( '{1}, <b>{2}</b> {3} <b>{4}</b>, <b>{6}</b> {7} {5}', $language->string( 'most_users' ),
                                                                                                                         $stats['most_users_online'],
                                                                                                                         $language->string( 'was_present', 0 ),
                                                                                                                         $core->formatTimeStamp( $stats['most_users_date'] ),
                                                                                                                         $language->string( 'was_present', 0 ),
                                                                                                                         $stats['most_users_online'],
                                                                                                                         $language->string( 'stats_person', 0 ) ),
                              'l_stats'    => $language->string( 'statistics' ),
                              'l_no_logged_users' => $language->string( 'no_logged_users' ),
                              'l_forum_posts'     => $language->string( 'forum_posts' ),
                              'l_forum_topics'    => $language->string( 'forum_topics' ),
                              'l_last_activity'   => $language->string( 'forum_last_activity' )
                              ) );

$page->drawHeader();
$template->draw( 'index_page' );
$page->drawFooter();